package cn.group.hotel2.controller;

import cn.group.hotel2.pojo.dto.CleanAddNewDTO;
import cn.group.hotel2.pojo.vo.CleanListCountVO;
import cn.group.hotel2.pojo.vo.CleanListItemVO;
import cn.group.hotel2.pojo.vo.CleanStandardVO;
import cn.group.hotel2.security.LoginPrincipal;
import cn.group.hotel2.service.ICleanService;
import cn.group.hotel2.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.List;

/**
 * 处理房间清洁相关请求的控制器
 * 
 * @author wcl
 * @version 0.0.1
 * @date 2022/11/26
 */
@Slf4j
@Valid
@RestController
@RequestMapping("/clean")
@Api(tags = "03 房间清洁管理模块")
public class CleanController {
    
    @Autowired
    private ICleanService cleanService;

    public CleanController() {
        log.debug("创建控制器对象：CleanController");
    }

    @ApiOperation("新增房间清洁")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult<Void> addNew(@Valid CleanAddNewDTO cleanAddNewDTO) {
        log.debug("开始处理【新增房间清洁】的请求，参数：{}", cleanAddNewDTO);
        cleanService.addNew(cleanAddNewDTO);
        log.debug("新增房间清洁成功！");
        return JsonResult.ok();
    }

    @ApiOperation("根据id删除客房")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name="id",value = "客房id",required = true,dataType = "long")
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult<Void> deleteById(@Range(min = 1,message = "删除客房失败,请填写有效的大于0的id") @PathVariable Long id) {
        log.debug("开始处理【根据id删除客房】的请求,参数:{}", id);
        cleanService.deleteById(id);
        log.debug("删除客房成功!");
        return JsonResult.ok();
    }

    @ApiOperation("根据id修改客房")
    @ApiOperationSupport(order = 300)
    @ApiImplicitParam(name="id",value = "客房id",required = true,dataType = "long")
    @PostMapping("/{id:[0-9]+}/update/{username}")
    public JsonResult<Void> updateById(@Range(min = 1,message = "修改客房失败,请填写有效的大于0的id")
                                              @PathVariable Long id,
                                              @PathVariable String username) {
        log.debug("开始处理【根据id修改客房】的请求,参数:{}", id);
        cleanService.updateCleanerAndStatusById(id, username);
        log.debug("修改客房成功!");
        return JsonResult.ok();
    }

    @ApiOperation("根据id修改客房状态")
    @ApiOperationSupport(order = 301)
    @ApiImplicitParam(name="id",value = "客房id",required = true,dataType = "long")
    @PostMapping("/{id:[0-9]+}/update")
    public JsonResult<Void> updateStatusById(@Range(min = 1,message = "修改客房失败,请填写有效的大于0的id")
                                             @PathVariable Long id) {
        log.debug("开始处理【根据id修改客房状态】的请求,参数:{}", id);
        cleanService.updateStatusById(id);
        log.debug("修改客房状态成功!");
        return JsonResult.ok();
    }

    @ApiOperation("根据id查询客房详情")
    @ApiOperationSupport(order = 400)
    @ApiImplicitParam(name = "id", value = "客房id", required = true, dataType = "long")
    @GetMapping("/{id:[0-9]+}/getStandardById")
    public JsonResult<CleanStandardVO> getStandardById(@PathVariable Long id) {
        log.debug("开始处理【根据id查询客房详情】的请求，参数：{}", id);
        CleanStandardVO clean = cleanService.getStandardById(id);
        return JsonResult.ok(clean);
    }
    
    @ApiOperation("查询房间清洁列表")
    @ApiOperationSupport(order = 410)
    @GetMapping("")
    public JsonResult<List<CleanListItemVO>> list(){
        log.debug("开始处理【查询房间清洁列表】请求,无参数");
        List<CleanListItemVO> list = cleanService.list();
        return JsonResult.ok(list);
    }

    @ApiOperation("根据所选的页数来分页查询")
    @ApiOperationSupport(order = 411)
    @ApiImplicitParam(name="pageNum",value = "需要跳过的记录数",required = true,dataType = "long")
    @GetMapping("/listByPageNum")
    public JsonResult<List<CleanListItemVO>> listByPageNum(@Range(min = 1,message = "查询客房失败,请填写有效的大于0的记录数")
                                                                         Long pageNum) {
        log.debug("开始处理【根据所选的页数来分页查询】的请求,参数:{}", pageNum);
        List<CleanListItemVO> list = cleanService.listByPageNum(pageNum);
        return JsonResult.ok(list);
    }

    @ApiOperation("查询列表所有的数据以统计其数量")
    @ApiOperationSupport(order = 450)
    @GetMapping("/count")
    public JsonResult<List<CleanListCountVO>> listCount(){
        log.debug("开始处理【查询列表所有的数据以统计其数量】请求,无参数");
        List<CleanListCountVO> list = cleanService.listCount();
        return JsonResult.ok(list);
    }

    @ApiOperation("查询处于待清洁状态下的清洁列表")
    @ApiOperationSupport(order = 412)
    @GetMapping("/wait")
    public JsonResult<List<CleanListItemVO>> listWaitClean(){
        log.debug("开始处理【查询处于待清洁状态下的清洁列表】请求,无参数");
        List<CleanListItemVO> list = cleanService.listWaitClean();
        return JsonResult.ok(list);
    }

    @ApiOperation("查询处于正在清洁状态下的清洁列表")
    @ApiOperationSupport(order = 413)
    @GetMapping("/current")
    public JsonResult<List<CleanListItemVO>> listCurrentClean(){
        log.debug("开始处理【查询处于正在清洁状态下的清洁列表】请求,无参数");
        List<CleanListItemVO> list = cleanService.listCurrentClean();
        return JsonResult.ok(list);
    }

    @ApiOperation("查询处于完成清洁状态下的清洁列表")
    @ApiOperationSupport(order = 414)
    @GetMapping("/finish")
    public JsonResult<List<CleanListItemVO>> listFinishClean(){
        log.debug("开始处理【查询处于完成清洁状态下的清洁列表】请求,无参数");
        List<CleanListItemVO> list = cleanService.listFinishClean();
        return JsonResult.ok(list);
    }

    @ApiOperation("根据所选的页数来分页查询")
    @ApiOperationSupport(order = 415)
    @ApiImplicitParam(name="pageNum",value = "需要跳过的记录数",required = true,dataType = "long")
    @GetMapping("/listWaitCleanByPageNum")
    public JsonResult<List<CleanListItemVO>> listWaitCleanByPageNum(@Range(min = 1, message = "查询客房失败,请填写有效的大于0的记录数")
                                                                   Long pageNum) {
        log.debug("开始处理【根据所选的页数来分页查询】的请求,参数:{}", pageNum);
        List<CleanListItemVO> list = cleanService.listWaitCleanByPageNum(pageNum);
        return JsonResult.ok(list);
    }

    @ApiOperation("查询列表所有的数据以统计其数量")
    @ApiOperationSupport(order = 451)
    @GetMapping("/listWaitCleanCount")
    public JsonResult<List<CleanListCountVO>> listWaitCleanCount(){
        log.debug("开始处理【查询列表所有的数据以统计其数量】请求,无参数");
        List<CleanListCountVO> list = cleanService.listWaitCleanCount();
        return JsonResult.ok(list);
    }

    @ApiOperation("根据所选的页数来分页查询")
    @ApiOperationSupport(order = 416)
    @ApiImplicitParam(name="pageNum",value = "需要跳过的记录数",required = true,dataType = "long")
    @GetMapping("/listCurrentCleanByPageNum")
    public JsonResult<List<CleanListItemVO>> listCurrentCleanByPageNum(@Range(min = 1,message = "查询客房失败,请填写有效的大于0的记录数")
                                                                   Long pageNum) {
        log.debug("开始处理【根据所选的页数来分页查询】的请求,参数:{}", pageNum);
        List<CleanListItemVO> list = cleanService.listCurrentCleanByPageNum(pageNum);
        return JsonResult.ok(list);
    }

    @ApiOperation("查询列表所有的数据以统计其数量")
    @ApiOperationSupport(order = 452)
    @GetMapping("/listCurrentCleanCount")
    public JsonResult<List<CleanListCountVO>> listCurrentCleanCount(){
        log.debug("开始处理【查询列表所有的数据以统计其数量】请求,无参数");
        List<CleanListCountVO> list = cleanService.listCurrentCleanCount();
        return JsonResult.ok(list);
    }

    @ApiOperation("根据所选的页数来分页查询")
    @ApiOperationSupport(order = 417)
    @ApiImplicitParam(name="pageNum",value = "需要跳过的记录数",required = true,dataType = "long")
    @GetMapping("/listFinishCleanByPageNum")
    public JsonResult<List<CleanListItemVO>> listFinishCleanByPageNum(@Range(min = 1,message = "查询客房失败,请填写有效的大于0的记录数")
                                                                   Long pageNum) {
        log.debug("开始处理【根据所选的页数来分页查询】的请求,参数:{}", pageNum);
        List<CleanListItemVO> list = cleanService.listFinishCleanByPageNum(pageNum);
        return JsonResult.ok(list);
    }

    @ApiOperation("查询列表所有的数据以统计其数量")
    @ApiOperationSupport(order = 453)
    @GetMapping("/listFinishCleanCount")
    public JsonResult<List<CleanListCountVO>> listFinishCleanCount(){
        log.debug("开始处理【查询列表所有的数据以统计其数量】请求,无参数");
        List<CleanListCountVO> list = cleanService.listFinishCleanCount();
        return JsonResult.ok(list);
    }
}
